import Vue from 'vue'
import Vuex from 'vuex'
import VueRouter from 'vue-router'
import Announace from "@/views/notice/Announace.vue"
import Comment from "@/views/discuss/Comment.vue"
import Research from "@/views/servey/Research.vue"
import Index from "@/components/Index.vue"
import Register from '@/views/user/Register.vue';
import Login from '@/views/user/Login.vue';
import Header from '@/components/Header.vue'
import Event from '@/views/event/Event.vue'
import AnnDetail from '@/views/notice/AnnDetail.vue'
import ComDetail from '@/views/discuss/ComDetail.vue'
import ResDetail from '@/views/servey/ResDetail.vue'
import EveDetail from '@/views/event/EveDetail.vue'

import MyDiscuss from '@/views/user/MyDiscuss.vue'
import MyApply from '@/views/user/MyApply.vue'
import MySuggest from '@/views/user/MySuggest.vue'
import Person from '@/views/user/Person.vue'
import Search from '@/views/Search.vue'

Vue.use(VueRouter)
Vue.use(Vuex)

const original = VueRouter.prototype.push

VueRouter.prototype.push = function push(loaction){
  return original.call(this,loaction).catch(err => err)
}

const routes = [
  {path: '/',component: Header,redirect: '/index',
 
      children: [
        {path: 'announace',component: Announace,},
        {path: 'comment',component: Comment},
        {path: 'research',component: Research},
        {path: 'index',component: Index},
        {path: 'event',component: Event,},
        {path: 'anndetail/:id',name: 'AnnDetail',component: AnnDetail,},
        {path: 'comdetail/:id',name: 'ComDetail',component: ComDetail,},
        {path: 'evedetail/:id',name: 'EveDetail',component: EveDetail,},
        {path: 'resdetail/:id',name: 'ResDetail',component: ResDetail,},
        {path: 'person',component: Person,},
        {path: 'mydiscuss',component: MyDiscuss},
        {path: 'myapply',component: MyApply},
        {path: 'mysuggest',component: MySuggest},
        {path: 'search/:keyword',name: 'Search',component: Search},
      ]
  },
  {path: '/login',component: Login},
  {path: '/register',component: Register},
  
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})



// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login'||from.path === '/login') {
//     next();
//   } else {
//     let token = localStorage.getItem('Authorization');
 
//     if (token === null || token === '') {
//       next('/login');
//     } else {
//       next();
//     }
//   }
// });

export default router
